const fn1Ts = () => console.log('被执行')
const fn2Ts = () => console.log('被拦截')

const onceTs = (fn:Function, errFn = function(){}) => {
  let firstRun = true
  // 返回一个函数实现闭包
  return function() {
    firstRun ? (fn(), firstRun = !firstRun) : errFn()
  }
}

const testTs = onceTs(fn1Ts, fn2Ts)
for(let i = 0 ; i< 5; i++) {
  testTs()
}
